Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vega-expression

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vega-expression

Vega expression parser and code generator.

  • 3.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
205K
increased by0.69%
Maintainers
2
Weekly downloads
 
Created

What is vega-expression?

The vega-expression npm package is a library used for parsing and evaluating expressions in the Vega visualization grammar. It allows users to define dynamic expressions for data transformations, visual encodings, and other operations within Vega specifications.

What are vega-expression's main functionalities?

Expression Parsing

This feature allows you to parse a string expression into an abstract syntax tree (AST). The parsed AST can then be used for further analysis or transformation.

const vegaExpression = require('vega-expression');
const code = 'datum.value * 2';
const ast = vegaExpression.parse(code);
console.log(ast);

Expression Evaluation

This feature allows you to evaluate a parsed expression within a given context. In this example, the expression 'datum.value * 2' is evaluated with datum.value set to 5, resulting in 10.

const vegaExpression = require('vega-expression');
const code = 'datum.value * 2';
const context = { datum: { value: 5 } };
const fn = vegaExpression.codegen({ code }).code;
const result = fn(context);
console.log(result); // 10

Custom Functions

This feature allows you to define and use custom functions within your expressions. In this example, a custom function 'customFunc' is defined to multiply the input by 3, and it is used within the expression.

const vegaExpression = require('vega-expression');
const code = 'customFunc(datum.value)';
const context = { datum: { value: 5 }, customFunc: (x) => x * 3 };
const fn = vegaExpression.codegen({ code }).code;
const result = fn(context);
console.log(result); // 15

Other packages similar to vega-expression

Keywords

FAQs

Package last updated on 21 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc